package com.vtuzx.kingdee.xqc_batch.component;

import com.vtuzx.batch.component.IVtuzxBatchComponent;
import com.vtuzx.core.bean.dto.VtuzxMap;
import com.vtuzx.core.utils.VtuzxUtil;
import com.vtuzx.kingdee.xqc_core.service.IVtuzxBasicService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


import com.vtuzx.batch.component.IVtuzxBatchComponent;

import java.util.Calendar;
import java.util.Date;

/**
 * 定时同步中台及时库存，月底最后一天
 */
@Component("sync_inventory")
public class SyncInventory implements IVtuzxBatchComponent {

    /** Logger */
    private static final Logger _logger = LoggerFactory.getLogger(SyncInventory.class);

    @Autowired
    private IVtuzxBasicService basicService;


    @Override
    public void execute(VtuzxMap param) throws Exception {
        String startDate = VtuzxUtil.getString(param, "from");
        Date from;
        Date to;
        Date now = new Date();
        if (VtuzxUtil.isEmpty(startDate)) {
            from = VtuzxUtil.calcDate(now, Calendar.HOUR_OF_DAY, -1);
            to = now;
        } else {
            from = VtuzxUtil.parseDate(startDate);
            to = VtuzxUtil.calcDate(from, Calendar.HOUR_OF_DAY, 1);
        }
        _logger.info(String.format("同步即时库存,时间:%s", VtuzxUtil.formatYmdHmsF(new Date())));
        basicService.syncInventory(from, to, 0);
        _logger.info(String.format("同步即时库存结束,时间:%s", VtuzxUtil.formatYmdHmsF(new Date())));
    }

}
